package zl.osimall.manager.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import zl.osimall.common.bean.RespBean;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/api/pic")
public class PicController {
    @Value("${zl.uploaddir}")
    public String uploaddir;

    @PostMapping("/upload")
    public RespBean upload(MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        filename = UUID.randomUUID().toString().replace("-", "") + filename;
        file.transferTo(new File(uploaddir + filename));
        return RespBean.ok("上传成功",filename);
    }
}
